package com.weipai.turnplate.controller;

import com.alibaba.fastjson.JSON;
import com.weipai.turnplate.enums.RetCode;
import com.weipai.turnplate.model.Turnplate;
import com.weipai.turnplate.model.Turnplaterollcall;
import com.weipai.turnplate.model.api.Response;
import com.weipai.turnplate.model.drawcode;
import com.weipai.turnplate.service.TurnplateService;
import org.apache.commons.lang.StringUtils;
import org.omg.CORBA.Request;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Author: 赵项阳
 * @Date: 2019/6/1 11:28
 * @Version 1.0
 */

@RestController
@CrossOrigin
public class TurnplateController {

    @Autowired
    private TurnplateService turnplateService;

    @RequestMapping(value = "/hello/lottery")
    public Response lottery(@NotNull(message = "抽奖码不能为空") String drawcode,
                            @NotNull(message = "用户手机号不能为空")String mobile,
                            @NotNull(message = "用户姓名不能为空")String name,
                            @NotNull(message = "用户的地址不能为空")String address,
                            @NotNull(message = "用户的省份不能为空")String provinces){
        return turnplateService.lottery(drawcode,name,mobile,address,provinces);

    }

    //修改抽奖码
    @RequestMapping(value = "/hello/update")
    public Response update(Integer[] id, String[] drawcode){
        return turnplateService.updateByDrawCode(id,drawcode);
    }


    //展示列表
    @RequestMapping(value = "/hello/list")
    public Response list(Integer visible,Integer size,Integer page){
        return turnplateService.list(visible,size,page);

    }
    //添加抽奖码
    @RequestMapping(value="/hello/save")
    public Response save(drawcode drawcode){
        return turnplateService.save(drawcode);
    }


    /**
     * 抽奖码图片的保存/修改
     * @param turnplate
     * @return
     */
    @RequestMapping(value = "/advertising/save", method = RequestMethod.POST)
    public Response saveimg(Turnplate turnplate){
        return null;
    }

    //批量修改
    @ResponseBody
    @RequestMapping(value = "/hello/batch")
    public Response updatebatch(@RequestBody String drawcode){
        Response response=new Response();
        if (StringUtils.isEmpty(drawcode)){
            response.setCode(RetCode.NULL);
            return response;
        }
        List<drawcode> demoList = JSON.parseArray(drawcode,drawcode.class);
        //return null;
        return turnplateService.updatebatch(demoList);

    }


    /**
     * 分页查询
     * @param page
     * @param grade
     * @return
     */
    @RequestMapping(value = "/customer/list", method = RequestMethod.GET)
    public Response list(String grade){
        return turnplateService.listinquire(grade);
    }

    /*
    * 保存图片
    * */
    @RequestMapping(value = "/hello/img")
    public Response img(String img,String id){


        return turnplateService.img(img,id);
    }

}
